# 基本切片语法：sequence[start:stop:step]
text = "Hello, World!"

# 基本切片
print(text[0:5])    # "Hello"
print(text[7:12])   # "World"
print(text[:5])     # "Hello" (从开始到索引5)
print(text[7:])     # "World!" (从索引7到结束)

# 负索引
print(text[-6:])    # "World!" (从倒数第6个字符开始)
print(text[:-1])    # "Hello, World" (除了最后一个字符)

# 步长
print(text[::2])    # "Hlo ol!" (每隔一个字符)
print(text[::-1])   # "!dlroW ,olleH" (反转字符串)

# 列表切片
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print(numbers[2:8:2])  # [2, 4, 6] (从索引2到8，步长为2)

# 切片赋值
numbers[2:5] = [10, 11, 12]  # 替换切片部分
print(numbers)  # [0, 1, 10, 11, 12, 5, 6, 7, 8, 9]
